Skip to content

[2/4] mm/pgalloc, arch/xtensa: Support BUILD_KERNEL on Xtensa - #19796

Draft
casaroli wants to merge 2 commits into
apache:masterfrom
casaroli:xtensa-split-2-kernel
Draft

[2/4] mm/pgalloc, arch/xtensa: Support BUILD_KERNEL on Xtensa#19796
casaroli wants to merge 2 commits into
apache:masterfrom
casaroli:xtensa-split-2-kernel

Conversation

@casaroli

@casaroli casaroli commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Part 2 of 4, split from #19772. Two independent pieces, no chip or board code.

mm/pgalloc gains 32 KB and 64 KB pages. It had 1 KB, 2 KB and 4 KB. The Espressif cache MMU has a fixed 64 KB page for external flash and 32 KB for external RAM.

arch/xtensa/src/common gains what BUILD_KERNEL needs and Xtensa lacked: a kernel stack for a user thread, a signal trampoline that returns through a system call, an initial register state that starts a user task at the right privilege, and the system call paths between the two worlds.

One detail worth review. A stack pointer carries a base save area in the 16 bytes below it, holding the caller's spilled a0-a3. Anything that builds or moves a stack pointer must leave it alone, so the signal trampoline reserves it explicitly rather than assuming the space below the pointer is free.

This adds no fork() or vfork() code and depends on nothing.

Impact

None on any existing configuration. Xtensa can be built with CONFIG_BUILD_KERNEL after this, but no chip provides an address environment yet, so nothing can be.

mm/pgalloc changes no default.

Testing

No kernel build is possible on this branch, so what is shown is that the common code compiles and does not disturb a flat build.

esp32s3-devkit:nsh builds clean on this branch alone.

esp32s3-devkit:ostest runs to the end on an ESP32-S3-DevKitC, WROOM-2 N32R8V:

ostest_main: Exiting with status 0

tools/checkpatch.sh -c -u -m -g passes.

@github-actions github-actions Bot added Arch: xtensa Issues related to the Xtensa architecture Area: Memory Management Memory Management issues Size: L The size of the change in this PR is large labels Aug 11, 2026
@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

@casaroli casaroli changed the title mm/pgalloc, arch/xtensa: Support BUILD_KERNEL on Xtensa [2/3] mm/pgalloc, arch/xtensa: Support BUILD_KERNEL on Xtensa Aug 11, 2026
@casaroli
casaroli marked this pull request as draft August 11, 2026 14:23
@casaroli
casaroli force-pushed the xtensa-split-2-kernel branch 2 times, most recently from 4dce990 to f87469e Compare August 11, 2026 15:30
@casaroli
casaroli marked this pull request as ready for review August 11, 2026 15:33
@github-actions github-actions Bot added Size: M The size of the change in this PR is medium and removed Size: L The size of the change in this PR is large labels Aug 11, 2026
@casaroli
casaroli force-pushed the xtensa-split-2-kernel branch from f87469e to f67dbec Compare August 11, 2026 20:06
@casaroli
casaroli marked this pull request as draft August 11, 2026 20:21
@casaroli

casaroli commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

The goal is #19798, together with the ESP32-S3 chip code and the user mode isolation that a kernel build needs.

But we have split it. Please review this one.

Add CONFIG_MM_PGSIZE == 32768 and 65536 to the page-size switch (and the
Kconfig help text). The 64 KB size matches the ESP32-S3 cache-MMU page
granularity, so an address-environment port there can use one mm_pgalloc()
page per cache-MMU page (naturally 64 KB-aligned by the granule allocator)
instead of coalescing several smaller pages. Inert for existing configs:
MM_PGSIZE is only used when CONFIG_MM_PGALLOC is enabled (BUILD_KERNEL).

Assisted-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
Add what a kernel build needs on Xtensa:  a crt0 for a user process, the
kernel stack allocation that a system call switches to, the syscall entry and
return path for an unprivileged caller, and the initial register state that
starts a user task at EL0 with its save area on the kernel stack.

On the ESP32-S3 the arch code that runs while the flash mapping is in flux
moves to IRAM, and the kernel heap is placed above the user .bss so that
up_allocate_kheap() and the user address environment do not overlap.

Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
@casaroli
casaroli force-pushed the xtensa-split-2-kernel branch from f67dbec to 2f8f2f9 Compare August 28, 2026 17:53
@casaroli casaroli changed the title [2/3] mm/pgalloc, arch/xtensa: Support BUILD_KERNEL on Xtensa [2/4] mm/pgalloc, arch/xtensa: Support BUILD_KERNEL on Xtensa Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: xtensa Issues related to the Xtensa architecture Area: Memory Management Memory Management issues Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant